"""The grouping of the various file acceptors used by the program"""

import os

class MockAcceptor(object):
    def __init__(self, base): pass
    def accept(self, elements): pass
    checkFile=lambda self, filePath: False

class SongAcceptor(object):
    name='Songs'
    fileTypes=['mp3']
    def __init__(self, base):
        self.__base=base
    def __fromFile(self, fileName):
        attsList=['Name', 'Album', 'Artist', 'Genre']
        retAtts={'Location': fileName}
        readList=[item.strip() for item in fileName.split('/')[:-1]]
        fileName=os.path.splitext(fileName)[0].split('/')[-1]
        fileSplit=[item.strip() for item in fileName.split('-')]
        if (len(fileSplit)>=4):
            try:
                retAtts['Track Number']=int(fileSplit[-2])
                del fileSplit[-2]
            except ValueError:
                pass
        for item in fileSplit:
            if item not in readList:
                readList.append(item)
        for att, read in zip(attsList, readList[::-1]):
            retAtts[att]=read
        return retAtts
    def accept(self, fileNames):
        """Accepts the elements into the base after conversion"""
        self.__base.addElements(self.__fromFile(fileName) for fileName
                                in fileNames)
    def checkFile(self, filePath):
        """Ensures that the file is of a valid extension"""
        return os.path.splitext(filePath)[1][1:] in self.fileTypes

definedClasses=[SongAcceptor]

def getAcceptor(name):
    for cls in definedClasses:
        if cls.name==name:
            return cls
    return MockAcceptor
